// 单例模式
function Singleton(name) {
  this.name = name
  this.instance = null
}
Singleton.getInstance = function(name) {
  if(!this.instance) {
    this.instance = new Singleton(name)
  }
  return this.instance
}
 
let obj1 = Singleton.getInstance('CXK')
let obj2 = Singleton.getInstance('XJT')
 
console.log(obj1===obj2)    // true
console.log(obj1)           // {name:CXK,password:123}
console.log(obj2)           // 输出的依然是{name:CXK,password:123}
